import smtplib

from email.mime.text import MIMEText
from email.header import Header


def send(sender, receivers, title, mimeText):
    # 三个参数：第一个为文本内容，第二个 plain 设置文本格式，第三个 utf-8 设置编码
    message = MIMEText(mimeText, 'plain', 'utf-8')
    message['From'] = Header("川理在线", 'utf-8')  # 发送者
    message['To'] = Header(receivers, 'utf-8')  # 接收者

    subject = title
    message['Subject'] = Header(subject, 'utf-8')

    try:
        smtpObj = smtplib.SMTP("smtp.mxhichina.com")
        smtpObj.login("postmaster@yaobiao.top", "18728579825yaoQQ")
        smtpObj.sendmail(sender, receivers, message.as_string())
        print("邮件发送成功")
    except smtplib.SMTPException as e:
        print(e)
        print("Error: 无法发送邮件")
